const path = require('path');
const express = require('express')
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
const server = require('http').createServer(app);
const io = require("socket.io")(server);

//https://socket.io/docs/v4/broadcasting-events/
//todo Please note that broadcasting is a server-only feature.
io.on("connection", socket => {

  //注意这里是 io.
  io.emit('all', '所有人都能收到的消息');

  //注意这里是 socket.
  socket.broadcast.emit('except self', '除了当前连接的人(socket),其它人都能收到的消息');
});

server.listen(3000);

